#!/bin/bash

# 获取当前系统的IP地址
IP_ADDRESS=$(hostname -I)

echo "${IP_ADDRESS}"

# monio地址
MINIO_URL="${MINIO_URL:-http://0.0.0.0:9000}"
MINIO_ACCESS="${MINIO_ACCESS:-vPyJQvpxZmOvs8hy}"
MINIO_SECRET="${MINIO_SECRET:-TtebpLo3J4iv0JFIu0E9drkauk8OiSlv}"

# pgsql地址
PG_URL="${PG_URL:-0.0.0.0:5432}"
PG_USERNAME="${PG_USERNAME:-myuser}"
PG_PASSWORD="${PG_PASSWORD:-mysecurepassword}"

# 启动monio
nohup /usr/local/bin/minio server /opt/minio/data --console-address "0.0.0.0:9001" > /dev/null 2>&1 &

# 启动pgsql
mkdir -p /var/run/postgresql/
chown -R postgres:postgres /var/lib/pgsql/data
chown postgres:postgres /var/run/postgresql/
chmod 0700 /var/lib/pgsql/data
su - postgres -c "pg_ctl -D /var/lib/pgsql/data start"

echo "授权密钥"
echo "$(echo -n "${IP_ADDRESS}" | md5sum | cut -d' ' -f1)"

# 运行服务
nohup /opt/jdk-11.0.21/bin/java -jar /data/xtc-easy-gateway-0.0.1-SNAPSHOT.jar > /dev/null 2>&1 &
nohup /opt/jdk-11.0.21/bin/java -DPG_URL="$PG_URL" -DPG_USERNAME="$PG_USERNAME" -DPG_PASSWORD="$PG_PASSWORD" -jar /data/xtc-authentication-0.0.1-SNAPSHOT.jar > /dev/null 2>&1 &
nohup /opt/jdk-11.0.21/bin/java -DPG_URL="$PG_URL" -DPG_USERNAME="$PG_USERNAME" -DPG_PASSWORD="$PG_PASSWORD" -DMINIO_URL="$MINIO_URL" -DMINIO_ACCESS="$MINIO_ACCESS" -DMINIO_SECRET="$MINIO_SECRET" -jar /data/x-asset-center-0.0.1-SNAPSHOT.jar > /dev/null 2>&1 &
nohup /opt/jdk-11.0.21/bin/java -DPG_URL="$PG_URL" -DPG_USERNAME="$PG_USERNAME" -DPG_PASSWORD="$PG_PASSWORD" -jar /data/x-data-center-0.0.1-SNAPSHOT.jar > /dev/null 2>&1 &
nohup /opt/jdk-11.0.21/bin/java -DPG_URL="$PG_URL" -DPG_USERNAME="$PG_USERNAME" -DPG_PASSWORD="$PG_PASSWORD" -jar /data/x-digital-view-0.0.1-SNAPSHOT.jar >  /dev/null 2>&1 &